﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using Nox.Amuse.MVVM;
using Nox.Amuse.View;

namespace Nox.Amuse.ViewModel
{
	public class DialogHostDataModel : ObservableObject
	{
		/// <summary>
		/// Stores the Owner Window for this dialog
		/// </summary>
		private Window Owner;

		/// <summary>
		/// Backing field for the Title property
		/// </summary>
		private string myTitle;
		/// <summary>
		/// Gets or sets the title bar text
		/// </summary>
		public string Title
		{
			get { return myTitle; }
            set { myTitle = value; base.RaisePropertyChanged("Title"); }
		}

		/// <summary>
		/// Backing field for the IconSource property
		/// </summary>
		private Uri myIconSource;
		/// <summary>
		/// Gets or sets the source for the dialog's icon
		/// </summary>
		public Uri IconSource
		{
			get { return myIconSource; }
            set { myIconSource = value; base.RaisePropertyChanged("IconSource"); }
		}

		/// <summary>
		/// Backing field for the Content property
		/// </summary>
		private UserControl myContent;
		/// <summary>
		/// Gets or sets the content to be displayed in this dialog
		/// </summary>
		public UserControl Content
		{
			get { return myContent; }
            set { myContent = value; base.RaisePropertyChanged("Content"); }
		}

		/// <summary>
		/// Creates a new DialogHostDataModel and sets the Owner property
		/// </summary>
		/// <param name="owner">The owner Window for the dialog</param>
		public DialogHostDataModel(Window owner)
		{
			Owner = owner;
		}

		/// <summary>
		/// Shows the Dialog and returns a result when completed
		/// </summary>
		/// <returns>A nullable bool with the result of the dialog</returns>
		public bool? ShowDialog()
		{
			var host = new DialogHostWindow
			{
				DataContext = this,
				Owner = this.Owner
			};
			var value = host.ShowDialog();
			// Clears the Window from memory
			host = null;
			return value;
		}
	}
}
